home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / incr.test < prev    next >
Text File  |  1993-07-12  |  3KB  |  87 lines

  1. # Commands covered:  lreplace
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/incr.test,v 1.5 93/07/12 11:34:43 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. catch {unset x}
  32.  
  33. test incr-1.1 {basic incr operation} {
  34.     set x 23
  35.     list [incr x] $x
  36. } {24 24}
  37. test incr-1.2 {basic incr operation} {
  38.     set x 106
  39.     list [incr x -5] $x
  40. } {101 101}
  41. test incr-1.3 {basic incr operation} {
  42.     set x "  -106"
  43.     list [incr x 1] $x
  44. } {-105 -105}
  45. test incr-1.3 {basic incr operation} {
  46.     set x "  +106"
  47.     list [incr x 1] $x
  48. } {107 107}
  49.  
  50. test incr-2.1 {incr errors} {
  51.     list [catch incr msg] $msg
  52. } {1 {wrong # args: should be "incr varName ?increment?"}}
  53. test incr-2.2 {incr errors} {
  54.     list [catch {incr a b c} msg] $msg
  55. } {1 {wrong # args: should be "incr varName ?increment?"}}
  56. test incr-2.3 {incr errors} {
  57.     catch {unset x}
  58.     list [catch {incr x} msg] $msg $errorInfo
  59. } {1 {can't read "x": no such variable} {can't read "x": no such variable
  60.     while executing
  61. "incr x"}}
  62. test incr-2.4 {incr errors} {
  63.     set x abc
  64.     list [catch {incr x} msg] $msg $errorInfo
  65. } {1 {expected integer but got "abc"} {expected integer but got "abc"
  66.     (reading value of variable to increment)
  67.     invoked from within
  68. "incr x"}}
  69. test incr-2.5 {incr errors} {
  70.     set x 123
  71.     list [catch {incr x 1a} msg] $msg $errorInfo
  72. } {1 {expected integer but got "1a"} {expected integer but got "1a"
  73.     (reading increment)
  74.     invoked from within
  75. "incr x 1a"}}
  76. test incr-2.6 {incr errors} {
  77.     proc readonly args {error "variable is read-only"}
  78.     set x 123
  79.     trace var x w readonly
  80.     list [catch {incr x 1} msg] $msg $errorInfo
  81. } {1 {can't set "x": variable is read-only} {can't set "x": variable is read-only
  82.     while executing
  83. "incr x 1"}}
  84.  
  85. catch {unset x}
  86. concat {}
  87.